<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="./js/vue.js"></script>
    <style>
        #app {
            border: 2px solid black;
            padding: 10px;
            margin-bottom: 400px;
        }

        .child {
            margin: 20px;
            padding: 10px;
            background-color: #cccccc;
        }
    </style>
</head>

<body>
    <div id="app">
        <h3>父组件范围</h3>
        <p>msg：{{msg}}</p>
        <input type="text" v-model="msg">
        <child-one></child-one>
        <child-two></child-two>
    </div>

    <template id="ChildOne">
        <div class="child">
            <h3>子组件one</h3>
            <p>msg：{{msg}}</p>
            <input type="text" v-model="msg">
            <p>info:{{info}}</p>
        </div>
    </template>
    <template id="ChildTwo">
        <div class="child">
            <h3>子组件two</h3>
            <p>msg：{{msg}}</p>
            <input type="text" v-model="msg">
            <p>arr:{{arr}}</p>
        </div>
    </template>
</body>
<script>
    // 全局混合
    Vue.mixin({
        data(){
            return {
                msg:"混入的数据变量"
            }
        },
        mounted() {
            console.log(this);
        },
    });

    var opt1 = {
        data() {
            return {
                arr: [1, 2, 3, 4]
            }
        }
    }
    var opt2 = {
        methods: {
            print() {
                console.log("混入方法")
            }
        },
    }

    Vue.component("ChildOne", {
        template: "#ChildOne",
        mixins:[opt1],
        data(){
            return {
                info:"childone"
            }
        }
    });
    Vue.component("ChildTwo", {
        template: "#ChildTwo",
        mixins:[opt1,opt2]
    });
    var vm = new Vue({
        el: "#app",

    });
</script>

</html>